package com.yc.ui.dialog;

import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

import com.yc.ui.MainUI;
import com.yc.ui.Order;
import com.yc.utils.DataDict;
import com.yc.utils.SWTUtil;

import org.eclipse.swt.widgets.Label;

import java.util.Map;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;

public class RoomDialog extends Dialog {

	protected Object result;
	protected Shell shell;
	private String r_id; // 门牌号
	private String r_type; // 类型
	private Object r_price; // 价格
	private String r_datail; // 描述
	private Object r_status; // 状态
	private Map<String, Object> roomMap; // 房间信息
	private Map<String, Object> map; // 登录信息

	/**
	 * Create the dialog.
	 * @param parent
	 * @param style
	 */
	public RoomDialog(Shell parent, int style, Map<String, Object> roomMap, Map<String, Object> map) {
		super(parent, style);
		setText("SWT Dialog");
		this.r_id = (String) roomMap.get("r_id");
		this.r_type = (String) roomMap.get("r_type");
		this.r_price = roomMap.get("r_price");
		this.r_datail = (String) roomMap.get("r_datail");
		this.r_status = roomMap.get("r_status");
		this.map = map;
		this.roomMap = roomMap;
		open();
	}

	/**
	 * Open the dialog.
	 * @return the result
	 */
	public Object open() {
		createContents();
		shell.open();
		shell.layout();
		Display display = getParent().getDisplay();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
		return result;
	}

	/**
	 * Create contents of the dialog.
	 */
	private void createContents() {
		shell = new Shell(getParent(), getStyle());
		shell.setSize(669, 488);
		shell.setText(getText());
		
		//界面居中显示
		SWTUtil.centerWindow(shell);

		Label lblNewLabel = new Label(shell, SWT.NONE);
		lblNewLabel.setBounds(44, 27, 76, 20);
		lblNewLabel.setText("房间号：");

		Label lblNewLabel_1 = new Label(shell, SWT.NONE);
		lblNewLabel_1.setBounds(44, 75, 76, 20);
		lblNewLabel_1.setText("类型：");

		Label lblNewLabel_2 = new Label(shell, SWT.NONE);
		lblNewLabel_2.setBounds(44, 131, 76, 20);
		lblNewLabel_2.setText("状态：");

		Label lblNewLabel_3 = new Label(shell, SWT.NONE);
		lblNewLabel_3.setBounds(154, 27, 76, 20);
		lblNewLabel_3.setText(r_id);

		Label lblNewLabel_4 = new Label(shell, SWT.NONE);
		lblNewLabel_4.setBounds(154, 75, 76, 20);
		lblNewLabel_4.setText(r_type);

		Label lblNewLabel_5 = new Label(shell, SWT.NONE);
		lblNewLabel_5.setBounds(154, 131, 76, 20);
		if("1".equals(r_status)) {
			lblNewLabel_5.setText("空闲");
		}else if("2".equals(r_status)) {
			lblNewLabel_5.setText("正在打扫");
		}else {
			lblNewLabel_5.setText("在住");

		}

		Label lblNewLabel_6 = new Label(shell, SWT.NONE);
		lblNewLabel_6.setBounds(44, 187, 76, 20);
		lblNewLabel_6.setText("费用:");

		Label lblNewLabel_7 = new Label(shell, SWT.NONE);
		lblNewLabel_7.setBounds(154, 187, 76, 20);
		lblNewLabel_7.setText(r_price.toString());

		Label lblNewLabel_8 = new Label(shell, SWT.NONE);
		lblNewLabel_8.setBounds(44, 236, 76, 20);
		lblNewLabel_8.setText("描述:");

		Label lblNewLabel_9 = new Label(shell, SWT.NONE);
		lblNewLabel_9.setBounds(154, 236, 129, 149);
		lblNewLabel_9.setText(r_datail + " ");

		Button btnNewButton = new Button(shell, SWT.NONE);
		btnNewButton.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				DataDict.stackLayout.topControl = DataDict.Order;
				MainUI.composite_1.layout();
				Order.xuanran(map, roomMap);
				shell.dispose();
			}
		});
		btnNewButton.setBounds(88, 391, 98, 30);
		btnNewButton.setText("预定");

		Button btnNewButton_1 = new Button(shell, SWT.NONE);
		btnNewButton_1.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				shell.dispose();
			}
		});
		btnNewButton_1.setBounds(348, 391, 98, 30);
		btnNewButton_1.setText("取消");

	}

}
